<?php

Raise::load('core.RaiseStaticClass');
Raise::load('core.RaiseFile');

/**
 * RaiseImageFont class
 * represents an image font
 *
 * @author Sam-Mauris Yong / hellclanner at live dot com
 * @license http://www.opensource.org/licenses/bsd-license New BSD License
 * @package phpraise.core.image
 * @since 1.2
 */
class RaiseImageFont extends RaiseStaticClass {

    const FONT1 = 1;
    const FONT2 = 2;
    const FONT3 = 3;
    const FONT4 = 4;
    const FONT5 = 5;

    private $value = null;

    /**
     * Create a new RaiseImageFont
     * @param RaiseFile|string $file The font to load
     */
    public function __construct($file){
        if($file instanceof RaiseFile){
            $file = $file->pathname();
        }
        $v = imageloadfont($file);
        if($v <= 5 || $v === false){
            throw new RaiseInvalidArgumentException('RaiseImageFont expects $file parameter to be a valid GD library font.');
        }
        $this->value = $v;
    }

    /**
     * Get the width of a character in pixels
     * @return integer The width of a character in pixels
     */
    public function width(){
        return imagefontwidth($this->value);
    }

    /**
     * Get the height of a character in pixels
     * @return integer The height of a character in pixels
     */
    public function height(){
        return imagefontheight($this->value);
    }

    /**
     * Return the resource identifier
     * @return integer The resource identifier
     */
    public function value(){
        return $this->value;
    }

}